import allure
from selenium.webdriver.common.by import By

from automation_ui.base.base import BasePage
from automation_ui.page.Promotion_manage import PromotionPage
from automation_ui.untils.log_util import logger


class Login(BasePage):
    __username = By.CSS_SELECTOR, "[name='username']"
    __password = By.CSS_SELECTOR, "[name='password']"
    __login = By.CSS_SELECTOR, ".el-button"

    @allure.step('登录')
    def login(self, name='manage', password='manage123'):
        """
        登录方法
        :param name: 用户名
        :param password: 密码
        :return:
        """
        self.url("https://litemall.hogwarts.ceshiren.com/#/login")
        self.clear(self.__username)
        self.send_key(self.__username, key=name)
        self.clear(self.__password)
        self.send_key(self.__password, key=password)
        self.click(self.__login)
        logger.info('登录')
        self.screencap()
        self.source()

        return PromotionPage(self.driver)
